package com.kmproject.haifu.mvp.model;

import android.app.Application;

import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import javax.inject.Inject;

import com.kmproject.haifu.mvp.contract.UserSetEditInfoContract;
import com.kmproject.haifu.mvp.model.api.service.UserService;
import com.kmproject.haifu.mvp.model.entity.ResultBean;
import com.kmproject.haifu.mvp.model.entity.beans.UserBean;

import java.io.File;

import io.reactivex.Observable;
import io.reactivex.functions.Function;
//import okhttp3.MediaType;
//import okhttp3.MultipartBody;
//import okhttp3.RequestBody;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 06/24/2019 11:47
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class UserSetEditInfoModel extends BaseModel implements UserSetEditInfoContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public UserSetEditInfoModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }
    @Override
    public Observable<ResultBean<UserBean>> qurUserInfo() {
        return mRepositoryManager.obtainRetrofitService(UserService.class).qurUserInfo().map(new Function<ResultBean<UserBean>, ResultBean<UserBean>>() {
            @Override
            public ResultBean<UserBean> apply(ResultBean<UserBean> userBeanResultBean) throws Exception {
                return userBeanResultBean;
            }
        });
    }

    @Override
    public Observable<ResultBean> updHeadPortrait(String avatar) {
        return mRepositoryManager.obtainRetrofitService(UserService.class).updHeadPortrait(avatar);
    }

//    @Override
//    public Observable<String> uploadFile(String url,File file) {
////        return mRepositoryManager.obtainRetrofitService(UserService.class).updHeadPortrait(multipartFile);
//        RequestBody requestFile =
//                RequestBody.create(MediaType.parse("application/otcet-stream"), file);
//        MultipartBody.Part body =
//                MultipartBody.Part.createFormData("file", file.getName(), requestFile);
//
//        return mRepositoryManager.obtainRetrofitService(UserService.class).uploadFile(url,body);
//    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }
}